<!--
 * @description  : 照片上传组件
 * @descriptionDetail: 照片上传组件
 * @copyright    : 浙江烟草
 * @author       : lt
 * @create       : 2022-09-27 09:58:58
-->
<template>
  <view>
    <u-form-item :label="params.label" label-position="top" :required="true">
      <view style="display:flex;flex-direction:column;">
        <m-upload
          index="picList"
          :width="150"
          :height="150"
          :fileList="picList"
          :uploadParam="{'fiGroupCode':'zmng-images', 'bizId': params.bizUuid}"
          @on-list-change="getImgs"
        ></m-upload>
        <view style="color:red;">
          {{ params.problemDesc }}
        </view>
      </view> 
    </u-form-item>
  </view>
</template>
<script>
import commonService from '@/service/internal/common.service';
import mUpload from "@/components/m-upload.vue";
export default {
  components: {mUpload,}, 
  props: {
    params:{
      label: String,
      problemDesc: String,
      bizUuid: String,
    },
  },
  data() {
    return {
      uploadFile: commonService.uploadFile,
      delUrl: commonService.deleteFile,
      picList: [], // 照片对象
      itemData:'',
      errorMessage: this.params.label + '至少上传三张',
    };
  },
  computed: {
  },
  created(){
    this.renderImages();
  },
  methods: {
    renderImages(){
      commonService.findFilesByBizId(this.params.bizUuid).then(r => {
        r.data.forEach(i => {
          i.src = `${commonService.downloadFile}?fileId=${i.gfiId}&tk=${uni.getStorageSync("tk")}`;
          i.filePath = i.src;
        });
        this.picList = r.data;
      });
    },
    getImgs(list, pos) {
      this.picList = [...list,];
      if(this.picList.length >= 3){
        let name = this.picList.map(it => it.gfiId);
        this.itemData = name.join(',');
      } else {
        this.itemData = "";
      }
    },
  },
};
</script>
<style lang="scss" scoped>

</style>